package cn.alcode.cardservice.util;

/**
 * Ajax工具类
 */
public class AjaxUtils {
    /**
     * 处理ajax结果
     *
     * @param action
     * @param <T>
     * @return
     */
    public static <T> AjaxResult<T> process(Func_T<T> action) {
        AjaxResult<T> ajaxResult = new AjaxResult<T>();
        ajaxResult.setSuccess(false);
        try {
            T result = action.invoke();
            ajaxResult.setSuccess(true);
            ajaxResult.setData(result);
        } catch (Exception e) {
            ajaxResult.setMessage(e.getMessage());
        }

        return ajaxResult;
    }
}
